#!/bin/bash

BASEDIR=/root/data

SRC_PATH=/media/kasim/DataSet/data
DST_PATH=/media/kasim/Data1/data/mixture


echo "${DST_PATH}/Syn90k"
if [ ! -d "${DST_PATH}/Syn90k" ];then
    mkdir -p ${DST_PATH}/Syn90k
    # cp -rf ${SRC_PATH}/Syn90k/shuffle_labels.txt ${DST_PATH}/Syn90k
    # cp -rf ${SRC_PATH}/Syn90k/label.txt ${DST_PATH}/Syn90k
    # tar -zxf ${SRC_PATH}/Syn90k/mjsynth.tar.gz -C ${DST_PATH}/Syn90k/
    # 原数据集图片数量太多空间不够，只用其中的1000000张（随机选取）
    python tools/data/textrecog/sync90k_to_10k.py ${SRC_PATH}/Syn90k/mjsynth.tar.gz ${SRC_PATH}/Syn90k/label.txt -o ${DST_PATH}/Syn90k --count 1000000
    python tools/data/utils/txt2lmdb.py -i ${DST_PATH}/Syn90k/label.txt -o ${DST_PATH}/Syn90k/label.lmdb
    # chmod a+wr ${DST_PATH}/Syn90k -Rf
fi


echo "${DST_PATH}/icdar_2013"
if [ ! -d "${DST_PATH}/icdar_2013" ];then
    mkdir -p ${DST_PATH}/icdar_2013
    cp -rf ${SRC_PATH}/icdar_2013/train_label.txt ${DST_PATH}/icdar_2013
    cp -rf ${SRC_PATH}/icdar_2013/test_label_1015.txt ${DST_PATH}/icdar_2013
    unzip -q ${SRC_PATH}/icdar_2013/Challenge2_Training_Task3_Images_GT.zip -d ${DST_PATH}/icdar_2013/Challenge2_Training_Task3_Images_GT
    unzip -q ${SRC_PATH}/icdar_2013/Challenge2_Test_Task3_Images.zip -d ${DST_PATH}/icdar_2013/Challenge2_Test_Task3_Images
    # chmod a+wr ${DST_PATH}/icdar_2013 -Rf
fi


echo "${DST_PATH}/icdar_2015"
if [ ! -d "${DST_PATH}/icdar_2015" ];then
    mkdir -p ${DST_PATH}/icdar_2015
    cp -rf ${SRC_PATH}/icdar_2015/train_label.txt ${DST_PATH}/icdar_2015
    cp -rf ${SRC_PATH}/icdar_2015/test_label.txt ${DST_PATH}/icdar_2015
    unzip -q ${SRC_PATH}/icdar_2015/ch4_training_word_images_gt.zip -d ${DST_PATH}/icdar_2015/ch4_training_word_images_gt
    unzip -q ${SRC_PATH}/icdar_2015/ch4_test_word_images_gt.zip -d ${DST_PATH}/icdar_2015/ch4_test_word_images_gt
    # chmod a+wr ${DST_PATH}/icdar_2015 -Rf
fi


echo "${DST_PATH}/IIIT5K"
if [ ! -d "${DST_PATH}/IIIT5K" ];then
    tar -zxf ${SRC_PATH}/IIIT5K/IIIT5K-Word_V3.0.tar.gz -C ${DST_PATH}/
    cp -rf ${SRC_PATH}/IIIT5K/train_label.txt ${DST_PATH}/IIIT5K
    cp -rf ${SRC_PATH}/IIIT5K/test_label.txt ${DST_PATH}/IIIT5K
    rm -rf ${DST_PATH}/IIIT5K/lexicon.txt
    rm -rf ${DST_PATH}/IIIT5K/*.mat
    rm -rf ${DST_PATH}/IIIT5K/README
    # chmod a+wr ${DST_PATH}/IIIT5K -Rf
fi


echo "${DST_PATH}/ct80"
if [ ! -d "${DST_PATH}/ct80" ];then
    mkdir -p ${DST_PATH}/ct80
    cp -rf ${SRC_PATH}/ct80/test_label.txt ${DST_PATH}/ct80
    unzip -q ${SRC_PATH}/ct80/CUTE80.zip -d ${DST_PATH}/ct80
    rm -rf ${DST_PATH}/ct80/gt.txt
#    unzip -q ${SRC_PATH}/ct80/CUTE80_Dataset.zip -d ${DST_PATH}/ct80
#    mv ${DST_PATH}/ct80/CUTE80 ${DST_PATH}/ct80/image
#    rm -rf ${DST_PATH}/ct80/Groundtruth
#    rm -rf ${DST_PATH}/ct80/__MACOSX
#    rm -rf ${DST_PATH}/ct80/Readme.txt
    # chmod a+wr ${DST_PATH}/ct80 -Rf
fi


echo "${DST_PATH}/svt"
if [ ! -d "${DST_PATH}/svt" ];then
    mkdir -p ${DST_PATH}/svt
    cp -rf ${SRC_PATH}/svt/test_label.txt ${DST_PATH}/svt
    unzip -q ${SRC_PATH}/svt/svt.zip -d ${DST_PATH}/svt
    python tools/data/textrecog/svt_converter.py ${DST_PATH}/svt/svt1
    mv ${DST_PATH}/svt/svt1/image ${DST_PATH}/svt/
    cp -rf ${DST_PATH}/svt/svt1/test_label.txt ${DST_PATH}/svt/
    rm -rf ${DST_PATH}/svt/__MACOSX
    rm -rf ${DST_PATH}/svt/svt1
    # chmod a+wr ${DST_PATH}/svt -Rf
fi


echo "${DST_PATH}/svtp"
if [ ! -d "${DST_PATH}/svtp" ];then
    mkdir -p ${DST_PATH}/svtp
    cp -rf ${SRC_PATH}/svtp/test_label.txt ${DST_PATH}/svtp
    cp -rf ${SRC_PATH}/svtp/svtp_test/IMG ${DST_PATH}/svtp/image
    # chmod a+wr ${DST_PATH}/svtp -Rf
fi

if [ ! -d "${BASEDIR}" ];then
    mkdir -p ${BASEDIR}
fi

if [ -d "${DST_PATH}" ];then
    if [ -h "${BASEDIR}/mixture" ];then
        rm -f ${BASEDIR}/mixture
    fi
    if [ ! -d "${BASEDIR}/mixture" ];then
        ln -s ${DST_PATH} ${BASEDIR}/mixture
    fi
fi
